﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThridGroup.ERP.DTO;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ThridGroup.ERP.ProductionSystem
{
    public class WorkmanshipService : ApplicationService, WorkmanshipIService
    {
        private readonly IRepository<Workmanship, int> _workmanshiprepository;
        public WorkmanshipService(IRepository<Workmanship, int> workmanshiprepository)
        {
            _workmanshiprepository = workmanshiprepository;
        }

        public async Task<int> AddWorkmanship(WorkmanshipDTO workmanship)
        {
            var list = ObjectMapper.Map<WorkmanshipDTO, Workmanship>(workmanship);
            var result = await _workmanshiprepository.InsertAsync(list);
            return result == null ? 0 : 1;
        }
        public async Task<int> DeleteWorkmanship(int workmanshipId)
        {
            var Del = _workmanshiprepository.DeleteDirectAsync(c => c.Id == workmanshipId);
            return Del == null ? 0 : 1;
        }
        public async Task<WorkmanshipDTO> FanWorkmanship(int workmanshipId)
        {
            var result = await _workmanshiprepository.FindAsync(c => c.Id == workmanshipId);
            var list = ObjectMapper.Map<Workmanship, WorkmanshipDTO>(result);
            return list;
        }
        public async Task<List<WorkmanshipDTO>> GetWorkmanship(int pageIndex = 1, int pageSize = 10)
        {
            var list = await _workmanshiprepository.GetListAsync();
            var result = ObjectMapper.Map<List<Workmanship>, List<WorkmanshipDTO>>(list);
            return result;
        }
        public async Task<int> UpdateWorkmanship(WorkmanshipDTO workmanship)
        {
            var list = ObjectMapper.Map<WorkmanshipDTO, Workmanship>(workmanship);
            var result = await _workmanshiprepository.UpdateAsync(list);
            return result == null ? 0 : 1;
        }
    }
}
